﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Project_9_License_Barna
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            //Close the application
            this.Close();
        }


        //----------------Global Variables-----------------------------------------------------------
        StreamReader inputFile = File.OpenText("Answers.txt");
        StreamReader inputStudent = File.OpenText("Student.txt");
        List<string> AnswerList = new List<string>();
        List<string> StudentList = new List<string>();


        //Method to read correct answers file
        private void ReadCorrect_Answers()
        {
            //Open the correct answer file
            //StreamReader inputFile = File.OpenText("Answers.txt");
            
            //Clear the list box
            //lstIncorrectArray.Items.Clear();

            //Read the scores into the list
            while (!inputFile.EndOfStream)
            {
                AnswerList.Add(inputFile.ReadLine());
            }

            //Close the file
            inputFile.Close();

            //foreach (string value in AnswerList)
            //{
            //    lstIncorrectArray.Items.Add(value);
            //}
        }

        //Method to read student answers file
        private void ReadStudent_Answers()
        {
            //Open the student answer file
            //StreamReader inputStudent = File.OpenText("Student.txt");

            //Read the student answers into the list
            while (!inputStudent.EndOfStream)
            {
                StudentList.Add(inputStudent.ReadLine());
            }

            //Close the file

            inputStudent.Close();
        }
        
        //Method to find amount of correct answers
        private void Correct_Answers()
        {
            //Variables
            int index = 0;
            int correct = 0;
            //foreach (string value in AnswerList)
            //    {
            //        lstIncorrectArray.Items.Add(value);
            //    }
            
                //for (correct = 0; correct < AnswerList.Count; index++)
                //foreach (string value in AnswerList)
                while (index < AnswerList.Count)
                {
                    //index = 2;
                    if (AnswerList[index] != StudentList[index])
                    {
                        index ++;
                       // lblCorrect.Text = index.ToString();
                    }

                    if (AnswerList[index] == StudentList[index])
                    {
                        index++;
                        correct++;
                    }


                    
                }

                if (correct >= 15)
                {
                    lblPF.Text = "Pass";
                }

                lblCorrect.Text = correct.ToString();
        }



        private void Incorrect_Answers()
        {
            //Variables
            int index = 0;
            int incorrect = 0;
            //foreach (string value in AnswerList)
            //    {
            //        lstIncorrectArray.Items.Add(value);
            //    }

            //for (correct = 0; correct < AnswerList.Count; index++)
            //foreach (string value in AnswerList)
            while (index < AnswerList.Count)
            {
                //index = 2;
                if (AnswerList[index] != StudentList[index])
                {
                    lstIncorrectArray.Items.Add(index);
                    index++;
                    incorrect++;
                    // lblCorrect.Text = index.ToString();
                }

                if (AnswerList[index] == StudentList[index])
                {
                    index++;
                }

                
            }

            if (incorrect > 5)
            {
                lblPF.Text = "Fail";
            }

            lblIncorrect.Text = incorrect.ToString();
        }
        //Check button method
        private void btnCheck_Click(object sender, EventArgs e)
        {

            ReadCorrect_Answers();
            ReadStudent_Answers();
            Correct_Answers();
            Incorrect_Answers();
        }
    }
}
